//
//  BBTKBaseCategooryViewController.m
//  BBTestKit
//
//  Created by aron on 2020/12/31.
//

#import "BBTKBaseCategooryViewController.h"
#import "BBTKBaseViewController.h"
#import <BBSDK/NSObject+BBFoundation.h>

@interface BBTKBaseCategooryViewController ()
@property (nonatomic, strong) NSMutableArray<BBTKSplitItem *> *items;
@end

@implementation BBTKBaseCategooryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

/**
 添加一个Cell和Cell对应的点击事件回调block
 @param title Cell显示名称
 @param callback 点击事件回调block
 @param category 分类
 */
- (void)bbtk_addActionWithCate:(NSString *)category
                         title:(NSString *)title
                      callback:(void(^)(void))callback {
    if (bb_isEmptyString(category)) {
        category = @"默认";
    }
    BBTKSplitItem *item = [self itemWithCategoryName:category];
    if (!item) {
        item = [BBTKSplitItem new];
        item.title = category;
        item.vcClass = BBTKBaseViewController.class;
        [self.items addObject:item];
    }
    
    // 添加子项目
    BBTKActionCellModel *subItem = [[BBTKActionCellModel alloc] initWithActionName:title actionCallBack:callback];
    [item.subItems addObject:subItem];
    
    [self setupDatas:self.items];
}

// MARK: - Helper

- (BBTKSplitItem *)itemWithCategoryName:(NSString *)categoryName {
    for (BBTKSplitItem *item in self.items) {
        if ([item.title isEqualToString:categoryName]) {
            return item;
        }
    }
    return nil;
}

// MARK: - Getter

- (NSMutableArray *)items {
    if (!_items) {
        _items = [NSMutableArray new];
    }
    return _items;
}

@end
